package cn.tedu.bonfire.front.content.controller;


import cn.tedu.bonfire.common.web.JsonResult;
import cn.tedu.bonfire.front.content.pojo.dto.UserLikeArticleDTO;
import cn.tedu.bonfire.front.content.pojo.dto.UserLikeCommentDTO;
import cn.tedu.bonfire.front.content.service.ILikeCollectService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@Slf4j
@RequestMapping("/LikeCollect")
@Api(tags = "5.点赞收藏模块")
public class LikeCollectController {

    @Autowired
   private ILikeCollectService likeCollectService;

    /**
     * 进行文章的点赞或收藏操作
     * @param likeArticleDTO
     * @return
     */
    @PostMapping("/NoteLikeOrCollect")
    @ApiOperation("文章点赞或者收藏")
    @ApiOperationSupport(order = 100)
    public JsonResult setLikeOrCollect(UserLikeArticleDTO likeArticleDTO) {
        likeCollectService.setArticleLikeOrCollect(likeArticleDTO);
        return JsonResult.ok();
    }

    /**
     * 进行文章的点赞/收藏取消操作
     * @param likeArticleDTO
     * @return
     */
    @PostMapping("/ArticleDeleteLikeOrCollect")
    @ApiOperation("文章取消点赞或者收藏")
    @ApiOperationSupport(order = 200)
    public JsonResult deleteLikeOrCollect(UserLikeArticleDTO likeArticleDTO) {
        likeCollectService.deleteLikeOrCollect(likeArticleDTO);
        return JsonResult.ok();
    }

    /**
     * 查询文章点赞/收藏状态
     * @param userId
     * @param articleId
     * @return
     */
    @GetMapping("/getNoteLikeCollectionState/{userId}/{noteId}")
    @ApiOperation("处理文章收藏功能")
    @ApiOperationSupport(order = 400)
    public JsonResult collectArticle(@PathVariable Long userId, @PathVariable Long articleId) {
        log.info("处理文章收藏功能...");
        Integer noteLikeCollection = likeCollectService.getArticleLikeCollection(userId,articleId);
        return JsonResult.ok(noteLikeCollection);
    }

    /**
     * 查询当前用户所有文章点赞状态
     * @param userId
     * @return
     */
    @GetMapping("/getAllNoteLike/{userId}")
    @ApiOperation("查询当前用户所有文章点赞状态")
    @ApiOperationSupport(order = 410)
    public JsonResult getAllArticleLike(@PathVariable Long userId) {
        log.info("开始获取当前用户所有文章点赞状态");
        Map<Long, Integer> allArticleLike = likeCollectService.getAllArticleLike(userId);
        return JsonResult.ok(allArticleLike);
    }


}
